#include <stdio.h>
#include <stdlib.h>	/* exit() */
#include <pthread.h>
#include <math.h>
#include <unistd.h>

/*
 * 打印线程ID
 */


pthread_t ntid;

void printids(const char * s)
{
	pid_t	pid;
	pthread_t	tid;

	pid = getpid();			// process
	tid = pthread_self();	// thread
	printf("%s pid %u tid %u (0x%x)\n", s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}

void * thr_fn(void * arg)
{
	printids("new thread: ");
	return ((void *) 0);
}

int main(void)
{
	int err;

	err = pthread_create(&ntid, NULL, thr_fn, NULL);
	if (err != 0)
		printf("pthread create fail.\n");

	printids("main thread:");
	sleep(1);
	exit(0);

	return 0;
}

/*
 
 main thread: pid 1320 tid 3078223552 (0xb779f6c0)
 new thread:  pid 1320 tid 3078220656 (0xb779eb70)
 
 */
